package com.ruoyi.project.poem.poemuser.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.project.poem.poemuser.domain.PoemUser;
import com.ruoyi.project.poem.poemuser.service.IPoemUserService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.web.page.TableDataInfo;

/**
 * 诗词用户Controller
 * 
 * @author shixiangwen
 * @date 2022-10-11
 */
@Controller
@RequestMapping("/poem/poemuser")
public class PoemUserController extends BaseController
{
    private String prefix = "poem/poemuser";

    @Autowired
    private IPoemUserService poemUserService;

    @RequiresPermissions("poem:poemuser:view")
    @GetMapping()
    public String poemuser()
    {
        return prefix + "/poemuser";
    }

    /**
     * 查询诗词用户列表
     */
    @RequiresPermissions("poem:poemuser:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(PoemUser poemUser)
    {
        startPage();
        List<PoemUser> list = poemUserService.selectPoemUserList(poemUser);
        return getDataTable(list);
    }

    /**
     * 导出诗词用户列表
     */
    @RequiresPermissions("poem:poemuser:export")
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(PoemUser poemUser)
    {
        List<PoemUser> list = poemUserService.selectPoemUserList(poemUser);
        ExcelUtil<PoemUser> util = new ExcelUtil<PoemUser>(PoemUser.class);
        return util.exportExcel(list, "poemuser");
    }

    /**
     * 新增诗词用户
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存诗词用户
     */
    @RequiresPermissions("poem:poemuser:add")
    @Log(title = "诗词用户", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(PoemUser poemUser)
    {
        return toAjax(poemUserService.insertPoemUser(poemUser));
    }

    /**
     * 修改诗词用户
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        PoemUser poemUser = poemUserService.selectPoemUserById(id);
        mmap.put("poemUser", poemUser);
        return prefix + "/edit";
    }

    /**
     * 修改保存诗词用户
     */
    @RequiresPermissions("poem:poemuser:edit")
    @Log(title = "诗词用户", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(PoemUser poemUser)
    {
        return toAjax(poemUserService.updatePoemUser(poemUser));
    }

    /**
     * 删除诗词用户
     */
    @RequiresPermissions("poem:poemuser:remove")
    @Log(title = "诗词用户", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(poemUserService.deletePoemUserByIds(ids));
    }
}
